import Vue from 'vue'
import Vuex from 'vuex'
// 加载，全局设置
import Setting from "../utils/setting";

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: uni.getStorageSync(Setting.constant.WYD_LOGIN) ? uni.getStorageSync(Setting.constant.WYD_LOGIN) : false,
		userInfo: {},
		deviceInfo: {}
	},
	mutations: {
		login(state, provider) {

			state.hasLogin = true;
			state.userInfo = provider;
			//缓存用户登陆状态
			uni.setStorage({
			    key: Setting.constant.WYD_LOGIN,  
			    data: true  
			}) 
			uni.setStorage({
			    key: 'userInfo',  
			    data: provider  
			}) 
			// console.log(state.userInfo);
		},
		
		logout(state) {
			state.hasLogin = false;
			state.userInfo = {};
			uni.removeStorage({
			    key: Setting.constant.WYD_LOGIN  
			})
			uni.removeStorage({  
                key: 'userInfo'  
            })
		},
		
		/**
		 * 存储设备信息
		 */
		setDeviceInfo(state, provider) {
			state.deviceInfo = provider;
			uni.setStorage({
			    key: Setting.constant.DECICEINFO,  
			    data: provider  
			}) 
		}
	},
	actions: {
	
	}
})

export default store